package com.assets.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.assets.R;

import java.util.List;

/**
 * Created by Administrator on 2019/5/7.
 */

public class Item_receive_Adapter extends BaseAdapter {
    private List<ReceiveData> data;
    private LayoutInflater layoutInflater;

    public Item_receive_Adapter(Context context, List<ReceiveData> data) {
        //传入的data，就是我们要在listview中显示的信息
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
    }

    public class Info {
        public TextView tv_no;//单号
        public TextView tv_dept;//部门
        public TextView tv_status;//状态
        public TextView tv_create_user;//创建人
        public TextView tv_receive_user;//领用人
        public TextView tv_num;//数量
        public TextView tv_apply_time;//申请时间
        public TextView tv_receive_time;//领用时间
        public TextView tv_num_name;//领用时间
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public ReceiveData getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Info info = new Info();
        convertView = layoutInflater.inflate(R.layout.item_receive, null);
        info.tv_no = (TextView) convertView.findViewById(R.id.tv_no);
        info.tv_dept = (TextView) convertView.findViewById(R.id.tv_dept);
        info.tv_status = (TextView) convertView.findViewById(R.id.tv_state);
        info.tv_create_user = (TextView) convertView.findViewById(R.id.tv_creator);
        info.tv_receive_user = (TextView) convertView.findViewById(R.id.tv_receiver);
        info.tv_apply_time = (TextView) convertView.findViewById(R.id.tv_apply_time);
        info.tv_receive_time = (TextView) convertView.findViewById(R.id.tv_receive_time);
        info.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
        info.tv_num_name = (TextView) convertView.findViewById(R.id.tv_num_name);
        info.tv_no.setText(data.get(position).getNo());
        info.tv_dept.setText(data.get(position).getDept());
        info.tv_status.setText(data.get(position).getStatus());
        info.tv_create_user.setText(data.get(position).getCreate_user());
        info.tv_receive_user.setText(data.get(position).getReceive_user());
        info.tv_apply_time.setText(data.get(position).getApple_time());
        info.tv_receive_time.setText(data.get(position).getReceive_time());
        info.tv_num.setText(data.get(position).getPlace());
        if (!TextUtils.isEmpty(data.get(position).getNumName())){
            info.tv_num_name.setText(data.get(position).getNumName());
        }
        return convertView;
    }
}
